package com.chijun.mform.field.impl;


import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chijun.mform.R;
import com.chijun.mform.create.mode.FormField;
import com.chijun.mform.field.BaseField;
import com.example.ccj.u.LogUtils;
import com.example.ccj.u.StringUtils;

import io.reactivex.ObservableEmitter;

/**
 * 说明文字
 * @author 驰珺
 * whechat   : chijun9
 * create at : 2024/12/23 15:43
 */
public class FieldFor08ShuoMingWenZi extends BaseField {
    public FieldFor08ShuoMingWenZi(){
        super();
    }

    @Override
    public View getWritelView(Context context, WriteFormClass writeFormClass) {
        FormField formField = writeFormClass.formField;
        LinearLayout layout = writeFormClass.view.findViewById(R.id.view_load_field_name_field_layout);
        layout.setVisibility(View.GONE);
        writeFormClass.fieldFullContentView.setVisibility(View.GONE);
        writeFormClass.fieldFullWriteErrorView.setVisibility(View.VISIBLE);
        writeFormClass.fieldFullWriteErrorView.setTextSize(12);
        writeFormClass.fieldFullWriteErrorView.setText(formField.getDefaultContent());
        if (formField.getTextColor() != 0) writeFormClass.fieldFullWriteErrorView.setTextColor(formField.getTextColor());
        return writeFormClass.view;
    }


    @Override
    protected View getShowFullView(Context context, FullClass fullModel) {
        //隐藏字段值
        fullModel.goneFieldNameView();
        fullModel.goneContentView();
        //设置值
        String fieldValue = fullModel.serverFullData.formOrdinaryFieldDataJsonObject.getString(String.valueOf(fullModel.formField.getId()));
        if (StringUtils.isEmpty(fieldValue)) {
            TextView textView = new TextView(context);
            textView.setText(fieldValue);
            textView.setTextColor(fullModel.formField.getTextColor());
            textView.setTextIsSelectable(true);//可选择
            fullModel.addCustomControl(textView);
        } else {
            LogUtils.e("说明字段未返回说明文字:",fullModel.formField.getId());
            return null;
        }
        return fullModel.layout;
    }


    /**
     * 字段设置界面
     * @param context 上下文
     * @param installClass 配置
     * @return 1
     */
    @Override
    protected View getFieldInstallView(Context context, InstallClass installClass) {
        ObservableEmitter<ViewGroup> emitter = installClass.emitter;

        emitter.onNext(installClass.getTextColorView());     //文本颜色
        emitter.onNext(installClass.getDefaultContentConfigView());    //默认值
        emitter.onNext(installClass.getIsPrintView());        //是否参与打印

        return installClass.v;
    }
}
